<template>
	<view>
		<!--封面-->
		
		<list-info :aid="aid" class="animated fadeIn fast" :playlistInfo="playlistInfo" ></list-info>
		
		<!--单曲列表-->
		<play-list class="animated fadeIn slow"  :privileges="privileges" 
		:aid="aid"  :playingid="id"  :playListId="playListId" ></play-list>
		
	</view>
</template>

<script>
	import listInfo from '../../components/playlist/list-info/list-info.vue';
	import playList from '../../components/playlist/play-list/play-list.vue';
	import jiazai from '../../components/home/jiazai/jiazai.vue';
	var app=getApp();
	export default {
		components:{
			listInfo,
			playList,
			jiazai
		},
		data() {
			return {
				//歌单信息名字封面
				playlistInfo:{},
				//歌单或者专辑id
				playListId:0,
				aid:0,
				//歌单
				privileges:[]			
			}
		},
		onLoad(options){
			const id=options.id;
			const aid=options.aid;
 			if(id){
				this.getplaylistItem(id);
				this.playListId=id;
			}
			else{
				this.getAlbum(aid);
				this.aid=aid;
			}	
		},
		methods: {
			//获取歌单信息以及列表
			async getplaylistItem(id){
				const result=await this.request({url: this.bsurl+'playlist/detail?id='+id});
				const playlistInfo={
					pic:result.playlist.coverImgUrl+'?param=150y150',
					name:result.playlist.name,
					authorpic:result.playlist.creator.avatarUrl+'?param=30y30',
					author:result.playlist.creator.nickname,
					playlistId:this.playListId,
				};
				const privileges=result.playlist.tracks.map(v=>{
				  return {
					id:v.id,
					name:v.name,
					author:v.ar[0].name
				  }
				});
				this.playlistInfo=playlistInfo;
				this.privileges=privileges;	
		    },
			//专辑信息
		    async getAlbum(aid){
		        const result=await this.request({url: this.bsurl+'album?id='+aid});
				const playlistInfo={
					pic:result.album.picUrl+'?param=150y150',
					name:result.album.name,
					authorpic:result.album.artist.picUrl+'?param=30y30',
					author:result.album.artist.name
				}
		        const privileges=result.songs.map(v=>{
					return {
					  id:v.id,
					  name:v.name,
					  author:v.ar[0].name
					}
		        });
				this.playlistInfo=playlistInfo;
				this.privileges=privileges;
				if(this.Finish()){
					setTimeout(()=>{
						this.isshow=false
					}, 1500);
				}
		    }
		}
	}
</script>

<style lang="less" scoped>
	
	
</style>
